<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Requests\Api\HelpRequest;
use App\Models\Help;
use App\Transformers\HelpTransformer;
use Illuminate\Http\Request;
use App\Http\Controllers\Api\Controller;

class HelpController extends Controller
{
    //添加帮助
    public function store(HelpRequest $request,Help $help){

        $help->title = $request->title;
        $help->contents = $request->contents;
        $help->save();

        return $this->response->array(['添加成功'])->setStatusCode(201);
    }

    public function update(Help $help,HelpRequest $request){
        $result=$help->update([
            $help->title=$request->title,
            $help->contents=$request->contents,
        ]);
        if ($result){
            return $this->response->array(['修改成功']);
        }else{
            return $this->response->array(['修改失败']);
        }
    }

    public function list(Help $help){
        $query=$help->query();
        $res = $query->paginate(20);
        return $this->response->paginator($res,new HelpTransformer());
    }

    public function delete(Help $help){
        $res=$help->delete();
        if ($res){
            return $this->response->array(['删除成功']);
        }else{
            return $this->response->array(['删除失败']);
        }
    }
}
